package com.itheima.exception;

import com.itheima.support.Result;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalExceptionInvoker {

    @ExceptionHandler
    public Result exceptionHandle(Exception e){
        String errorMsg = e.getMessage();
        if(ObjectUtils.isEmpty(errorMsg) == false && errorMsg.length() > 200){
            errorMsg = errorMsg.substring(0,200);
        }
        e.printStackTrace();
        return new Result(false,errorMsg);
    }

}
